package com.leyou.seckill.controller;

import com.leyou.seckill.dto.SecKillOrderDTO;
import com.leyou.seckill.service.SecKillService;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SecKillPortalController {

    @Autowired
    private SecKillService secKillService;
    /**
     * 获取服务端时间
     * @return
     */
    @GetMapping("/portal/time")
    public ResponseEntity<String> getTime(){

        return ResponseEntity.ok(DateTime.now().toString("yyyy-MM-dd HH:mm:ss"));
    }

    /**
     * 用户的秒杀操作
     * @param secKillOrderDTO
     * @return
     */
    @PostMapping("/portal/secKill")
    public ResponseEntity<Long> secKillGoods(@RequestBody SecKillOrderDTO secKillOrderDTO){
        Long orderId = secKillService.secKillGoods(secKillOrderDTO);
        return ResponseEntity.ok(orderId);
    }
}
